<template>
	<view class="content">
    <u-collapse
        @change="change"
        @close="close"
        @open="open"
    >
		<view class="" v-for="(item,index) in productList" :key="index">
      <!--          :title="index + 1+'、'+item.tit"-->
      <u-collapse-item
      :title="item.tit"
      :name="item.tit"
      >
			<view class="title fw">
        {{item.tit}}
        <text v-if="userType==2 && flowN<=4" style=" float: right;
        font-size: 11px;
        color: #3F51B5;
        font-weight: bold;"  @click="goAdd(item.id)">
        添加/修改
      </text>
      </view>

			<view class="message" v-for="items,indexs in item.list" :key="indexs">
				<!-- @click="productSelect(index,indexs,items)" -->
				<view class="messageBar disb aic">
					<text style="width: 45%">{{items.categoryName}}</text>
					<view class="right disp aic">
						<text v-if="items.resultValue">{{items.resultValue}}</text>
						<image src="../../static/images/preat/right.png" mode="" v-if="userType!=3"></image>
						<u-switch v-model="items.isShow" size="20" v-else></u-switch>
					</view>
				</view>
			</view>

      </u-collapse-item>

		</view>
    </u-collapse>
<!--		<view class="title tac fw">17 补充资料</view>-->
		<u-action-sheet :actions="list" :title="title" :show="show" @select='select' @close='show=false'></u-action-sheet>
		<view class="" v-if="userType==3&&!cant">
      <u-divider color="#fa3534" half-width="200" border-color="#6d6d6d">默认为通过，如打上未通过项，选择驳回提交</u-divider>
			<view class="upBtn fz12 colorf disa aic">
				<view class="btn tac" @click="canPass">通过</view>
				<view class="btn noBtn tac" @click="cantPass">选项驳回</view>
			</view>
			<view class="shows fz12 disp aic">
				<view class="disp aic">
					<u-switch v-model="nochecked" size="20" disabled></u-switch>
					<text class="saying">通过</text>
				</view>
				<view class="disp aic">
					<u-switch  v-model="checked" size="20" disabled></u-switch>
					<text class="saying">不达标(选项驳回)</text>
				</view>
			</view>
		</view>
		<view class="sureBtn tac colorf fz12" v-if="userType==2 && flowN<=4" @click="goNext">
      确定已完成资料录入
    </view>
    <view class="sureBtn2 tac colorf fz12" v-if="userType==2 && flowN>=5">
      已转权证
    </view>
	</view>
</template>

<script>
	import {dataList,getPublicitySelectListByClassName,cantPassSelect} from "../../api/search.js"
	export default {
		data() {
			return {
				cant:0,
				nochecked:false,
				checked:true,
				show:false,
				list:[],
				userType:uni.getStorageSync('userInfo').userType,
				orderId:null,
        flowN:null,
				title:'',
				userSelect:null,
				fatherNum:null,
				childNum:null,
				age:26,
				data:[],
				user:uni.getStorageSync('userInfo'),
				productList:[
					{name:'完成按揭房信贷公式表',tit:'按揭房信贷',list:[],id:1},
					{name:'完成保单贷公式表',tit:'保单贷',list:[],id:2},
					// {name:'完成个人贴息贷款公式表',tit:'创业贴息贷款',list:[]},
					{name:'完成工薪贷公式表',tit:'工薪贷',list:[],id:4},
					{name:'完成公积金贷公式表',tit:'公积金贷',list:[],id:5},
					// {name:'完成企业贴息贷款公式表',tit:'企业信用贷款',list:[]},
					{name:'完成全款车按揭车信贷公式表',tit:'全款车按揭车信贷',list:[],id:7},
					{name:'完成商业商住楼写字楼厂房一抵押公式表',tit:'商业商住楼写字楼厂房一抵押',list:[],id:8},
					{name:'完成商业商住楼写字楼二次抵押公式表',tit:'商业商住楼写字楼二次抵押',list:[],id:9},
					{name:'完成商业写字楼按揭贷款公式',tit:'商业写字楼按揭贷款',list:[],id:10},
					{name:'完成税贷公示表',tit:'企业税贷',list:[],id:11},
					{name:'完成企业流水贷公式表',tit:'企业流水贷',list:[],id:12},
					{name:'完成企业发票贷公式表',tit:'企业发票贷',list:[],id:13},
					{name:'完成住宅按揭贷款公式表',tit:'住宅按揭贷',list:[],id:14},
					{name:'完成住宅抵押公式表',tit:'住宅抵押贷',list:[],id:15},
					{name:'完成住宅二次抵押公式表',tit:'住宅二次抵押贷',list:[],id:16},
				]
				
			};
		},
		onLoad(option) {
      console.log(option)
			this.orderId = option.id
      this.flowN = option.flowN
			this.cant = option.cant
		},
		onShow() {
			this.productList.forEach(v => {
        v.list = []
      })
      setTimeout(() => {
        this.getDetail(this.orderId)
      }, 400)
		},
		methods:{
      open(e) {
         console.log('open', e)
      },
      close(e) {
         console.log('close', e)
      },
      change(e) {
        console.log('close', e)
      },
			//性别
			getSex(i){
				if(i==1){
					return '男'
				}
				if(i==2){
					return '女'
				}
				if(i==3){
					return '未知'
				}
			},
			//点击选择事件
			click(i){
				this.show = true
				this.userSelect = i
				if(i==1){
					this.title = '选择性别'
					this.list = [{name:'男',num:1},{name:'女',num:2},{name:'未知',num:3}]
				}
				if(i==2){
					this.title = '选择户籍'
					this.list = [{name:'重庆市内'},{name:'重庆市外'}]
				}
				if(i==3){
					this.title = '选择户口'
					this.list = [{name:'农村户口'},{name:'城镇户口'}]
				}
			},
			//驳回
			cantPass(){
				let arr = []
				this.productList.forEach(v => {
					v.list.forEach(s => {
						let obj = {}
						if(s.isShow){
							obj.id = s.id
							obj.categoryName = s.categoryName
							obj.resultValue = s.resultValue
							obj.isPassed = 0
							obj.typeName = s.typeName
							arr.push(obj)
						}
					})
				})
				let parmas = {
					orderId:this.orderId,
					isPass:0,
					itemList:arr
				}
				cantPassSelect(parmas).then(res => {
					if(res.code==0){
						uni.$u.toast('已驳回！')
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}else{
						uni.$u.toast(res.msg)
					}
				})
			},
			//通过
			canPass(){
				let parmas = {
					orderId:this.orderId,
					isPass:1,
					itemList:[]
				}
				cantPassSelect(parmas).then(res => {
					if(res.code==0){
						uni.$u.toast('已通过！')
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}else{
						uni.$u.toast(res.msg)
					}
				})
			},
			//确认
			select(e){
				if(this.userSelect==1){
					this.user.sex = e.num
				}
				if(this.userSelect==2){
					this.user.censusRegister = e.name
				}
				if(this.userSelect==3){
					this.user.registeredHk = e.name
				}
			},
			//产品确认
			productSure(e){
				this.productList[this.fatherNum].list[this.childNum].resultValue = e.name
			},
			getDetail(id){
				dataList({id:id}).then(res => {
          // let arr = []
          // for(let k in res.data){
          //    let obj = {name:'',tit:'',list:[]}
          //    console.log(k)
          //    obj.name = k
          //    obj.tit = k
          //    obj.list = res.data[k]
          //    arr.push(obj)
          // }
          // this.productList = arr
					let arr = []
          console.log(res)
					for(let k in res.data){
					  arr.push(res.data[k])
					}
					arr.forEach(v => {
						v.forEach(s => {
							this.productList.forEach(e => {
								if(e.name == s.typeName){
									s.isShow = false
									e.list.push(s)
                  //this.open(e.tit)
								}
							})
						})
					})
          //console.log(this.productList)
				})
			},
			//去添加
			goAdd(i){
        uni.navigateTo({
          url:`/pages/information/housing?id=${i}&orderId=${this.orderId}`
        })
			},
			goNext(){
				uni.navigateTo({
					url:`/pages/search/checkResult?id=${this.orderId}`
				})
			}
		}
	}
</script>

<style lang="scss">
.content{
	padding: 10rpx 0;
	background-color: #f7f7f7;
	min-height: 100vh;
	.title{
		padding: 30rpx;
		color: #333;
	}
	.addBtn{
		line-height: 50rpx;
		margin: 0 30rpx 30rpx;
		color: #323CDD;;
		background-color: #e6e7ff;
	}
	.message{
    height: auto;
		.messageBar{
			font-size: 12px;
			padding: 20rpx 30rpx;
			background-color: #fff;
			margin-bottom: 5rpx;
			.right{
				image{
					width: 20rpx;
					height: 30rpx;
					margin-left: 20rpx;
				}
			}
		}
	}
	.upBtn{
		padding: 20rpx;
		.btn{
			width: 200rpx;
			line-height: 60rpx;
			border-radius: 30rpx;
			background-color: rgb(38, 150, 80);
		}
		.noBtn{
			background-color: #ff5500;
		}
	}
	.shows{
		padding: 20rpx;
		.saying{
			margin: 0 10rpx;
		}
	}
	.sureBtn{
		width: 80%;
		line-height: 80rpx;
		margin: 40rpx auto;
		border-radius: 40rpx;
		background-color: #3d55da;
	}
  .sureBtn2{
    width: 80%;
    line-height: 80rpx;
    margin: 40rpx auto;
    border-radius: 40rpx;
    background-color: silver;
  }
  .r-f-right{

  }
}
</style>
